/**
 * 
 */
package kr.co.insoft.publicmesh.controller.comparison.monthly;

import java.util.List;

import kr.co.insoft.core.model.comparison.monthly.MonthlyEntityModel;
import kr.co.insoft.core.model.comparison.monthly.MonthlyResultEntityModel;
import kr.co.insoft.core.service.comparison.monthly.MonthlyService;
import kr.co.insoft.core.service.configration.vender.VenderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author IN-SOFT Inc. Park Jong Taek(jtpark@in-soft.co.kr)
 * 
 */
@Controller
@RequestMapping(value = "comparison/monthly")
public class MonthlyController {

	final String TILES_PAGE_PREFIX = "tiles/comparison/monthly";
	final String SINGLE_PAGE_PREFIX = "comparison/monthly";
	
	@Autowired
	VenderService venderService;
	
	@Autowired
	MonthlyService monthlyService;

	/**
	 * Comparison Monthly
	 * 
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "view", method = RequestMethod.GET)
	public String main(
			Model model,
			@RequestParam(value = "ip", defaultValue = "N", required = false) String ip)
			throws Exception {
		
		model.addAttribute(new MonthlyEntityModel());
		model.addAttribute("venderList", venderService.getComboList());
		
		if (ip.equals("Y"))
			return SINGLE_PAGE_PREFIX + "/view";

		return TILES_PAGE_PREFIX + "/view";
	}
	
	/**
	 * Comparison Monthly Chart View
	 * 
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "chart", method = RequestMethod.POST)
	public @ResponseBody List<MonthlyResultEntityModel> getChartData(
			@ModelAttribute("monthlyEntityModel") MonthlyEntityModel monthlyEntityModel)
			throws Exception {
		
		return monthlyService.getChartData(monthlyEntityModel);
	}
	
}
